
#!/bin/bash


#优化的转化镜像方案(在指定负载下优化镜像)

set -e

# 源镜像和目标镜像
SRC_IMAGE="docker.io/randkin/llm-environment:latest"
TARGET_IMAGE="randkin/llm-environment:esgzv2"

# 模型和脚本目录
MODEL_DIR="$HOME/models/TinyLlama-1.1B-Chat-v1.0-GGUF"
SCRIPT_DIR="$(pwd)"
LOG_PATH="$SCRIPT_DIR/cold_start_access_log.json"

echo "========================================="
echo "  ctr-remote 镜像转化为 eStargz (冷启动负载)"
echo "  源镜像: $SRC_IMAGE"
echo "  目标镜像: $TARGET_IMAGE"
echo "  日志输出: $LOG_PATH"
echo "========================================="


# 转化镜像为 eStargz 并记录访问日志
sudo ctr-remote image optimize --oci \
    --entrypoint='[ "python" ]' \
    --args='[ "/app/cold_start_test.py" ]' \
    --mount=type=bind,source=$MODEL_DIR,destination=/model,options=bind:ro \
    --mount=type=bind,source=$SCRIPT_DIR,destination=/app,options=bind:ro \
    --record-out=$LOG_PATH \
    $SRC_IMAGE \
    $TARGET_IMAGE

echo "转化完成，访问日志已保存到: $LOG_PATH"
#!/bin/bash
set -e

# 配置参数
SOURCE_IMAGE="docker.io/randkin/llm-environment:latest"
TARGET_IMAGE="randkin/llm-environment:esgzv2"
MODEL_DIR="$HOME/models/TinyLlama-1.1B-Chat-v1.0-GGUF"
MODEL_FILE="tinyllama-1.1b-chat-v1.0.Q4_K_M.gguf"
FULL_MODEL_PATH="$MODEL_DIR/$MODEL_FILE"
SCRIPT_NAME="cold_start_test.py"

echo "Using shared cold_start_test.py from repo root"



echo "开始优化镜像..."
sudo ctr-remote image optimize --oci \
    --mount=type=bind,source=$MODEL_DIR,destination=/model,options=bind:ro \
    --mount=type=bind,source=$(pwd),destination=/app,options=bind:ro \
    --record-out=model_access_log.json \
    --entrypoint='[ "python" ]' \
    --args="[ \"/app/$SCRIPT_NAME\" ]" \
    $SOURCE_IMAGE \
    $TARGET_IMAGE

echo "========================================="
echo "  优化完成!"
echo "  生成的eStargz镜像: $TARGET_IMAGE"
echo "  文件访问日志: model_access_log.json"
echo "========================================="



# 不再创建/删除临时脚本，使用仓库中的 `cold_start_test.py`